<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:p="http://primefaces.org/ui">


    <ui:define name="content">

        <h:panelGroup >
            <h:form id="form"  >
                <p:panel id="panIx"  >
                    <f:facet name="header" >
                        <h:outputLabel value="List of Items and Services"></h:outputLabel>
                    </f:facet>

                    <h:panelGrid columns="1" styleClass="alignTop" >
                        <h:panelGrid columns="4" >
                            <p:commandButton ajax="false" 
                                             value="Add Fees For Selected Items" action="#{itemController.createItemFessForItemsWithoutFee}" >
                            </p:commandButton>

                            <p:commandButton 
                                ajax="false" value="Fix Items Totals" action="#{itemController.updateSelectedItemFees}" >
                            </p:commandButton>
                            <p:commandButton 
                                ajax="false" value="Fix Discount Allowed Property" action="#{itemController.updateSelectedFeesForDiscountAllow}" >
                            </p:commandButton>

                            <p:commandButton 
                                ajax="false" value="Refresh Items" action="#{itemController.refreshInvestigationsAndServices}" >
                            </p:commandButton>

                        </h:panelGrid>
                        <p:panel >
                            <p:dataTable  value="#{itemController.investigationsAndServices}" 
                                          var="i"   
                                          rowKey="#{i.id}" 
                                          selection="#{itemController.selectedList}" 
                                          rowIndexVar="s"
                                          rows="20"
                                          paginator="true"
                                          paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                          rowsPerPageTemplate="20,50,100,500,1000,1500"
                                          >

                                <p:column  selectionMode="multiple" style="width: 10px;">                            
                                </p:column>

                                <p:column   sortBy="#{i.name}" width="200"
                                            filterMatchMode="contains" filterBy="#{i.name}" >  
                                    <f:facet name="header">
                                        <h:outputLabel value="Item Name" />
                                    </f:facet>
                                    <h:outputLabel value="#{i.name}"/>
                                </p:column>

                                <p:column sortBy="#{i.institution.name}" width="200"
                                          filterMatchMode="contains" filterBy="#{i.institution.name}">
                                    <f:facet name="header">
                                        <h:outputLabel value="Institution" />
                                    </f:facet>
                                    <h:outputLabel value="#{i.institution.name}" ></h:outputLabel>
                                </p:column>

                                <p:column sortBy="#{i.department.name}" width="120"
                                          filterMatchMode="contains" filterBy="#{i.department.name}">
                                    <f:facet name="header">
                                        <h:outputLabel value="Department" />
                                    </f:facet>
                                    <h:outputLabel value="#{i.department.name}" ></h:outputLabel>
                                </p:column>
                                <p:column sortBy="#{i.dblValue}" width="80"
                                          filterMatchMode="contains" filterBy="#{i.dblValue}">
                                    <f:facet name="header">
                                        <h:outputLabel value="Total Fee" >

                                        </h:outputLabel>
                                    </f:facet>
                                    <h:outputLabel value="#{i.total}" >
                                        <f:convertNumber pattern="#,##0.00" ></f:convertNumber>
                                    </h:outputLabel>
                                </p:column>
                                <p:column style="text-align: right;">
                                    <f:facet name="header">
                                        <h:outputLabel value="Fees" />
                                    </f:facet>

                                    <p:dataTable  value="#{i.itemFeesActive}" var="itfe" >
                                        <p:column headerText="Name">
                                            <p:outputLabel value="#{itfe.name}" ></p:outputLabel>
                                        </p:column>
                                        <p:column headerText="Type">
                                            <p:outputLabel value="#{itfe.feeType}" ></p:outputLabel>
                                        </p:column>
                                        <p:column headerText="Discount">
                                            <p:outputLabel value="#{itfe.discountAllowed?'Allowed':'Not Allowed'}" ></p:outputLabel>
                                        </p:column>
                                        <p:column headerText="Fee">
                                            <p:outputLabel value="#{itfe.fee}" >
                                                <f:convertNumber pattern="#,##0.00" ></f:convertNumber>
                                            </p:outputLabel>
                                        </p:column>
                                        <p:column headerText="Foreigner">
                                            <p:outputLabel value="#{itfe.ffee}" >
                                                <f:convertNumber pattern="#,##0.00" ></f:convertNumber>  
                                            </p:outputLabel>
                                        </p:column>
                                    </p:dataTable>


                                </p:column>

                                <p:column headerText="Actions" width="60">
                                    <p:commandButton ajax="false" value="Edit" action="${itemFeeManager.toManageItemFees()}"  actionListener="#{viewController.makeBulkFeesAsPreviousPage()}">
                                        <f:setPropertyActionListener value="#{i}" target="#{itemFeeManager.item}" ></f:setPropertyActionListener>
                                    </p:commandButton>
                                </p:column>

                            </p:dataTable>
                        </p:panel>




                    </h:panelGrid>

                </p:panel>
            </h:form>

        </h:panelGroup>

    </ui:define>

</ui:composition>
